var numberOfArithmeticSlices = function (A) {
if (A.length < 3) return 0;
var dp = [];
if (A[2] - A[1] === A[1] - A[0]) {
dp[2] = 1;
} else {
dp[2] = 0;
}
var result = dp[2];
for (var i = 3; i < A.length; i++) {
if (A[i] - A[i - 1] === A[i - 1] - A[i - 2]) {
dp[i] = dp[i - 1] + 1;
result += dp[i];
} else {
dp[i] = 0;
}
}
return result;
};
var canPartition = function (nums) {
var sum = nums.reduce((a, b) => a + b, 0);
if (sum % 2) return false;
sum = sum / 2;
var n = nums.length;
var dp = [];
while (dp.push(new Array(sum + 1).fill(0)) < n + 1) ;
for (var i = 0; i < n + 1; i++) {
dp[i][0] = 1;
}
for (var i = 1; i < n + 1; i++) {
for (var j = 1; j < sum + 1; j++) {
if (dp[i - 1][j]) dp[i][j] = 1;
if (j >= nums[i - 1] && dp[i - 1][j - nums[i - 1]]) dp[i][j] = 1;
}
}
// console.log(dp);
return !!dp[n][sum];
};